1
Oltre i prompt singoli: la transizione verso flussi di lavoro complessi
AI010Lesson 4
00:00

La fine del "mega-prompt"

Nelle fasi iniziali dello sviluppo dei modelli linguistici (LLM), gli utenti spesso cercavano di "infilare" ogni istruzione, vincolo e punto dati in un singolo, enorme prompt. Sebbene intuitivo, questo approccio porta a overfitting, costi elevati in termini di token e crea una "scatola nera" in cui risolvere i guasti diventa quasi impossibile.

L'industria sta evolvendo verso Chaining dei prompt. Questo approccio modulare considera il modello linguistico come una serie di lavoratori specializzati piuttosto che un generico sovraccarico.

Perché concatenare i prompt?

  • Affidabilità:Suddividere un compito complesso in sottotask gestibili riduce drasticamente i tassi di allucinazioni.
  • Integrazione:Permette di inserire dinamicamente dati da strumenti esterni (come un database JSON interno o un'API) durante lo svolgimento del flusso di lavoro.
  • Efficienza dei costi:Invii solo il contesto necessario per ogni passaggio specifico, risparmiando token.
Regola empirica: suddivisione dei compiti
Un prompt dovrebbe gestire un compito specifico. Se ti trovi a usare più di tre dichiarazioni "e poi" in un'unica istruzione di prompt, è arrivato il momento di concatenarle in chiamate separate.
pipeline.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute pipeline.
>
Knowledge Check
Why is "Dynamic Context Loading" (fetching data mid-workflow) preferred over putting all possible information into a single system prompt?
It makes the model run faster on local hardware.
It prevents model confusion and reduces token costs by only providing necessary data.
It allows the model to ignore the system instructions.
Challenge: Designing a Safe Support Bot
Apply prompt chaining principles to a real-world scenario.
You are building a tech support bot. A user asks for the manual of a "X-2000 Laptop."

Your task is to define the logical sequence of prompts needed to verify the product exists in your database and ensure the final output doesn't contain prohibited safety violations.
Step 1
What should the first two actions in your pipeline be immediately after receiving the user's message?
Solution:
1. Input Moderation: Check if the prompt contains malicious injection attempts. Evaluate as $ (N/Y) $.
2. Entity Extraction: Use a specialized prompt to extract the product name ("X-2000 Laptop") from the raw text.
Step 2
Once the entity is extracted, how do you generate the final safe response?
Solution:
1. Database Lookup: Query the internal DB for "X-2000 Laptop" manual data.
2. Response Generation: Pass the user query AND the retrieved DB data to the LLM to draft an answer.
3. Output Moderation: Run a final check on the generated text to ensure no safety policies were violated before sending it to the user.